
import Row from "../../qbasics/basics/Row";
import Block from "../../qbasics/basics/Block";
import StrTo from "../../qbasics/utils/StrTo";
export default class Word{

    constructor(core){
        this.core=core;
    }
    /**
     * 用ID 获取 文字
     * @param id
     * @returns {string}
     */
    findWord(id){
        let block=  this.dict.findIdea(id)
        let row= block.find(1)
        let res="";
        if(row.isValue(4,"2")){
            res=res+this.findWord(row.find(1))
            res=res+this.findWord(row.find(2))
        }else {
            res=  StrTo.numToUtf8(row.find(1));
        }
        return res;
    }
    /**
     * 添加字
     */
    findWordId(word,type){
        if(ids.length=0){
            return "";
        }
        let typeId=""
        if(!type){
            let ids = this.findStrIds(type);
              typeId = this.addWords(ids);
        }
        let wordIds = this.findStrIds(word);
        let wordId = this.addWords(wordIds);

        let block = new Block();
        let row= new Row(wordId,"","",typeId)
        let id = this.core.dict.searchIdea(row,block);

        if(!id){
              id =this.core.dict.addIdea(row,block);
        }

        return id;
    }


    /**
     * 添加词
     */
    findWordIds(ids){
        let block = new Block();
        if(ids.length>1){
            if(ids.length=3){
                let row= new Row(ids[0],ids[1],ids[2],"")
                   return  this.core.dict.searchIdea(row,block);
            }else {
                let row= new Row(ids[0],ids[1] ,"","")
               let  id=  this.core.dict.searchIdea(row,block);
                // todo 暂时没用想到这里怎么做
                if(ids.length>3){
                   for(let i=2;i<ids.label;i++){
                       let row= new Row(id,ids[i] ,"","")
                          id=  this.core.dict.searchIdea(row,block);
                   }
                }
                return  id;
            }
        }

       return idsp[0];

    }

    findStrIds(srt){
        let srts=srt.split("");
        let strIds=new Array();
        let block = new Block();
        srts.forEach(str=>{
            let  strNum=StrTo.utf8ToNum(str)

            let row= new Row(strNum,"","","")
            let searchIdea = this.core.dict.searchIdea(row,block);

            if(searchIdea){
                searchIdea =this.core.dict.addIdea(row,block);
            }

            strIds.add(searchIdea);
        })
        return strIds;
    }




}
